package com.ruoyi.custom.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.custom.domain.FinanceData;
import com.ruoyi.custom.service.IFinanceDataService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 财务数据Controller
 * 
 * @author ruoyi
 * @date 2025-08-15
 */
@RestController
@RequestMapping("/custom/finance")
public class FinanceController extends BaseController
{
    @Autowired
    private IFinanceDataService financeDataService;

    /**
     * 查询财务数据列表
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:list')")
    @GetMapping("/list")
    public TableDataInfo list(FinanceData financeData)
    {
        startPage();
        List<FinanceData> list = financeDataService.selectFinanceDataList(financeData);
        return getDataTable(list);
    }

    /**
     * 导出财务数据列表
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:export')")
    @Log(title = "财务数据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FinanceData financeData)
    {
        List<FinanceData> list = financeDataService.selectFinanceDataList(financeData);
        ExcelUtil<FinanceData> util = new ExcelUtil<FinanceData>(FinanceData.class);
        util.exportExcel(response, list, "财务数据");
    }

    /**
     * 获取财务数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(financeDataService.selectFinanceDataById(id));
    }

    /**
     * 新增财务数据
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:add')")
    @Log(title = "财务数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FinanceData financeData)
    {
        return toAjax(financeDataService.insertFinanceData(financeData));
    }

    /**
     * 修改财务数据
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:edit')")
    @Log(title = "财务数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FinanceData financeData)
    {
        return toAjax(financeDataService.updateFinanceData(financeData));
    }

    /**
     * 删除财务数据
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:remove')")
    @Log(title = "财务数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(financeDataService.deleteFinanceDataByIds(ids));
    }

    /**
     * 获取财务统计数据
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:stats')")
    @GetMapping("/stats")
    public AjaxResult getFinanceStats(FinanceData financeData)
    {
        return success(financeDataService.getFinanceStats(financeData));
    }

    /**
     * 获取渠道分析数据
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:channel')")
    @GetMapping("/channel/analysis")
    public AjaxResult getChannelAnalysis(FinanceData financeData)
    {
        return success(financeDataService.getChannelAnalysis(financeData));
    }

    /**
     * 获取渠道概览数据
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:channel')")
    @GetMapping("/channel/overview")
    public AjaxResult getChannelOverview()
    {
        return success(financeDataService.getChannelOverview());
    }

    /**
     * 获取渠道趋势数据
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:channel')")
    @GetMapping("/channel/trend")
    public AjaxResult getChannelTrend(FinanceData financeData)
    {
        return success(financeDataService.getChannelTrend(financeData));
    }

    /**
     * 获取星级分析数据
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:star')")
    @GetMapping("/star/analysis")
    public AjaxResult getStarAnalysis(FinanceData financeData)
    {
        return success(financeDataService.getStarAnalysis(financeData));
    }

    /**
     * 获取星级概览数据
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:star')")
    @GetMapping("/star/overview")
    public AjaxResult getStarOverview()
    {
        return success(financeDataService.getStarOverview());
    }

    /**
     * 获取星级分布数据
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:star')")
    @GetMapping("/star/distribution")
    public AjaxResult getStarDistribution()
    {
        return success(financeDataService.getStarDistribution());
    }

    /**
     * 获取星级趋势数据
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:star')")
    @GetMapping("/star/trend")
    public AjaxResult getStarTrend(FinanceData financeData)
    {
        return success(financeDataService.getStarTrend(financeData));
    }

    /**
     * 批量星级升级
     */
    @PreAuthorize("@ss.hasPermi('custom:finance:star:upgrade')")
    @Log(title = "星级升级", businessType = BusinessType.UPDATE)
    @PostMapping("/star/upgrade")
    public AjaxResult batchStarUpgrade(@RequestBody FinanceData financeData)
    {
        return toAjax(financeDataService.batchStarUpgrade(financeData));
    }
}
